package dao;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class UpdateFriend {
    public boolean updateFriend(String userid, String friendid, int statement) {
        Connection conn=null;
        ResultSet res=null;
        try {
            Properties info=new Properties();
            info.load(new FileInputStream("src\\sql.properties"));
            String user=info.getProperty("user");
            String password=info.getProperty("password");
            String Driver=info.getProperty("Driver");
            String url=info.getProperty("url");
            //注册驱动
            Class.forName(Driver);
            //获取连接
            conn= DriverManager.getConnection(url,user,password);
            String sql1 ="update friendlist set statement = '"+statement+"' where user_id='"+userid+"' and friend_id='"+friendid+"'";
            String sql2 ="update friendlist set statement = '"+statement+"' where user_id='"+friendid+"' and friend_id='"+userid+"'";
            PreparedStatement statement1=conn.prepareStatement(sql1);
            boolean flag=false;
            int update=statement1.executeUpdate();
            if(update==1)
                flag=true;
            statement1 = conn.prepareStatement(sql2);
            update = statement1.executeUpdate();
            if(update==1)
                flag=true;
            return  flag;
        }catch(SQLException e){
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }
}
